package com.chauhai.android.mymapdemo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.chauhai.android.batsg.mymap.MapLocation;
import com.chauhai.android.batsg.mymap.MapView;
import com.chauhai.android.batsg.util.ActivityUtil;
import com.chauhai.android.batsg.util.ImageUtil;

/**
 * Demonstrate the usage of MapView and MapLocation.
 * <p>
 * Some locations are added by java code, some ones are added via xml layout.
 * @author umbalaconmeogia
 */
public class MyMapDemoActivity extends Activity {

  protected MapView map;

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    MapLocation[] locations = createLocations();

    map = (MapView) findViewById(R.id.map);
    map.setMapImage(ImageUtil.loadBitmapFromResource(getResources(), R.drawable.map));
    map.addLocations(locations);
  }

  private MapLocation[] createLocations() {
    try {
      MapLocation[] locations = new MapLocation[] {
          new StateLocation(this, 125, 69, R.drawable.my_house_normal, R.drawable.my_house_selected, "My house"),
          new StateLocation(this, 493, 565, "her_house_normal.png", "her_house_selected.png", "Her house"),
          new StateLocation(this, 720, 685, "Pond 1"),
          new ZoomLocation(this, 300, 300, 150, 100, "zoom_normal.png", "zoom_selected.png", "zoom 1"),
      };
      return locations;
    } catch (Exception e) {
      ActivityUtil.closeOnError(this, "Error createLocations");
      e.printStackTrace();
    }
    return null;
  }

  /**
   * Called when user clicks Zoom out button.
   * @param v
   */
  public void zoomOut(View v) {
    map.zoom(map.getZoomRatio() - .1f);
  }

  /**
   * Called when user clicks Zoom in button.
   * @param v
   */
  public void zoomIn(View v) {
    map.zoom(map.getZoomRatio() + .1f);
  }

  public void gotoNext(View v) {
    Intent intent = new Intent(this, NextMapActivity.class);
    startActivity(intent);
  }
}